<?php

namespace app\index\model;

use think\Db;

/**
 * @author xjy
 */
class SaleoreportModel
{
    //销售订单列表
    static public function getList($param, $titles = null, $function = null,$groupby='id')
    {
        $where=[];
        $db = Db::table('store_skusale_report')
                ->alias('a');
        if (!empty($param['sku'])) {
            $where['sku']=$param['sku'];
        }
        if (!empty($param['country'])) {
            $where['country']=$param['country'];
        }
        if (!empty($param['shop'])) {
            $where['shop']=$param['shop'];
        }
        $fields='id,shop,country,sku,cname,sku_state,cycle_stage,sum(daily_average) daily_average,sum(7day_average) 7day_average,sum(14day_average) 14day_average,'
                . 'sum(21day_average) 21day_average,sum(28day_average) 28day_average,'
                . 'sum(year_saleamount) year_saleamount,sum(saleamount) saleamount,sum(total_money) total_money';
        $db->field($fields);
        $db->where($where);
        if($groupby){
            $db->group($groupby);
        }
        
        $db->order('id','desc');
        return \app\common\service\ToolService::downOrReturn($db, $param, $titles,$function);
    }
}
